﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Kiss.Wpf.OrderService;

namespace Kiss.Wpf
{
    /// <summary>
    /// Interaction logic for main window.
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void getButton_Click(object sender, RoutedEventArgs e)
        {
            OrderServiceClient service = new OrderServiceClient();
            Customer[] customers = service.GetCustomersByCity(cityTextBox.Text);
            dataGrid.ItemsSource = customers;
        }

        private void updateButton_Click(object sender, RoutedEventArgs e)
        {
            OrderServiceClient service = new OrderServiceClient();
            Customer customer = (Customer)dataGrid.SelectedValue;
            if(!customer.City.EndsWith("X"))
                customer.City = customer.City + "X";
            else
                customer.City = customer.City.Remove(customer.City.Length - 1);
            service.UpdateCustomer(customer);
        }
    }
}
